package com.crm.system.service.impl.cluePoolManager;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.cluePoolManager.ClueReturn;
import com.crm.model.vo.cluePoolManager.ClueReturnVO;
import com.crm.service.cluePoolManager.ClueReturnDbService;
import com.crm.system.service.cluePoolManager.ClueReturnService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/8 13:05
 */
@Service
public class ClueReturnServiceImpl implements ClueReturnService {
    @Autowired
    ClueReturnDbService clueReturnDbService;

    /**
     * 线索池详情-线索清单-退回记录
     * @param pageIndex     ---页码
     * @param pageSize      ---分页大小
     * @param clueId        ---线索Id
     * @return
     */
    @Override
    public DhPageInfo<ClueReturnVO> selectClueReturnVOList(Integer pageIndex, Integer pageSize, String clueId) {
        if(pageIndex!=null&&pageSize!=null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<ClueReturnVO> clueReturnVOList = clueReturnDbService.selectClueReturnVOList(clueId);
        PageInfo<ClueReturnVO> pageInfo = new PageInfo<>();
        return new DhPageInfo<ClueReturnVO>(pageInfo, clueReturnVOList);
    }

    /**
     * 新增一条线索退回/释放记录
     * @param accountId      ---账号ID
     * @param clueId         ---线索ID
     * @param returnType     ---退回类型(1:管理端收回; 2:客户端释放)
     * @param returnReason   ---退回原因
     * @param cluePoolFromId ---线索池id: 从哪个池子释放的池子id
     * @param cluePoolToId   ---线索池id: 释放到哪个池子的池子id
     * @return
     */
    @Override
    public Boolean insertClueReturn(String accountId, String clueId, String returnType, String returnReason,String cluePoolFromId,String cluePoolToId) {
        ClueReturn clueReturn = new ClueReturn();
        clueReturn.setClueReturnId(CommonUtils.getGUID());//主键
        clueReturn.setReturnPeopleId(accountId);//退回人id
        clueReturn.setReturnTm(new Date());//退回时间
        clueReturn.setReturnReason(returnReason);//退回原因
        clueReturn.setReturnType(returnType);//退回类型--1:管理端收回; 2:客户端释放
        clueReturn.setCluePoolFromId(cluePoolFromId);
        clueReturn.setCluePoolToId(cluePoolToId);
        clueReturn.setClueId(clueId);//线索ID
        return clueReturnDbService.insertClueReturn(clueReturn) > 0;
    }
}
